<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .red {
            background: red;
        }

        .blue {
            background: blue;
        }
    </style>
</head>

<body>
    <button id="btn1" data-show-ype="show">btn1</button>
    <button id="btn2" data-show-ype="show">btn2</button>
    <script>
        let toggleClass = (className) => {
            console.log('window', this)
            return function (ev) {
                console.log('dom', this)
                console.log(this.getAttribute("data-show-ype"))
                console.log(ev)
                console.log(className)
                ev.target.classList.toggle(className);
            }
        }
        
        btn1.addEventListener("click", toggleClass('red')) //会直接执行 那就返回一个函数
        btn2.addEventListener("click", toggleClass('blue'))
    </script>
</body>

</html>